﻿using UnityEngine;
using System.Collections;

public class EnemyManager : MonoBehaviour {
    
    public GameObject enemy;
    public float spawnTime = 3f;
    public Transform[] spawnPoints;

    PlayerHealth playerHealth;

	// Use this for initialization
	void Start () {
        playerHealth = GameObject.FindGameObjectWithTag(Tags.player).GetComponent<PlayerHealth>();
        InvokeRepeating("Spawn", spawnTime, spawnTime);
	}

    void Spawn()
    {
        if (playerHealth.currentHP <= 0)
            return;

        int spawnPointIndex = Random.Range(0, spawnPoints.Length);
        Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
    }
}
